package com.longrise.android.byjk.plugins.tabthird;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.R;
import com.longrise.android.byjk.plugins.tabthird.invoice.ConsumeDetailActivity;
import com.longrise.android.byjk.widget.view.BBswipeRefreshLayout;
import com.longrise.common.base.BaseActivity2;
import com.longrise.common.utils.AppUtil;

import java.util.List;


/**
 * Created by Administrator on 2018/1/14.
 * 我的订单界面
 */

public class MineOrderManagerActivity extends BaseActivity2<OrderManagerPresenter> implements OrderManagerContract.View,SwipeRefreshLayout.OnRefreshListener, MineOrderAdapter.OnItemClickListener {

    public static final String MINEORDERMANAGER = "mineordermanager";
    private RecyclerView mRv;
    private BBswipeRefreshLayout mSwipeRefreshLayout;
    private LinearLayout ll_order_null;
    private MineOrderAdapter mAdapter;
    private List<MineOrderBean> mListBeans;
    private EntityBean[] mListBean;
    private View mHeadView;


    @Override
    public int getContentViewId(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_mine_order_manager;
    }

    @Override
    public void initView() {
        mRv = (RecyclerView) findViewById(R.id.mine_order_irv);
        mSwipeRefreshLayout = (BBswipeRefreshLayout) findViewById(R.id.mine_order_swipelayout);
        ll_order_null = (LinearLayout) findViewById(R.id.ll_order_null);
        initRec();
        mPresenter.getOrderListData();
    }

    public void initRec() {
        mSwipeRefreshLayout.setOnRefreshListener(this);
        mHeadView = View.inflate(mContext, R.layout.item_mine_appoint_headerview, null);
        mAdapter = new MineOrderAdapter();
        mAdapter.addHeaderView(mHeadView);
        mRv.setLayoutManager(new LinearLayoutManager(mContext));
        mRv.setAdapter(mAdapter);
        setToolbarTitle(AppUtil.getString(R.string.mine_book));
        mAdapter.setOnItemClickListener(this);
    }


    @Override
    public void onToolbarBackClick() {
        finish();
    }

    @Override
    public void onRefresh() {
        mPresenter.getOrderListData();
    }

    @Override
    public void onClick(String orderid,int orderState,int buyType) {

        if(4 == buyType){
            Intent intent = new Intent(mContext, MineOrderDetailActivity.class);
            intent.putExtra(MineOrderDetailActivity.ORDERDETAILID,orderid);
            intent.putExtra(MineOrderDetailActivity.ORDERDETAILSTATE,orderState);
            startActivity(intent);
        }else {
            Intent intent1 =new Intent(mContext, ConsumeDetailActivity.class);
            intent1.putExtra(ConsumeDetailActivity.INTENT_EXTRA_PARAMS,orderid);
            startActivity(intent1);
        }
    }

    @Override
    public void refreshData(EntityBean bean) {
        mListBean = (EntityBean[]) bean.get("result");
        mAdapter.refreshData(mListBean);
    }

    @Override
    public void setRefreshing(boolean isRefreshing) {
        mSwipeRefreshLayout.setRefreshing(isRefreshing);
    }
}
